var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2UIManager = require("UIManager");
var $2ccUtil = require("ccUtil");
var $2BaseUI = require("BaseUI");
var r;
var l;
var c;
(function (e) {
  e[e.None = 0] = "None";
  e[e.Dark = 1] = "Dark";
  e[e.Dim = 2] = "Dim";
})(r || (r = {}));
(function (e) {
  e[e.None = 0] = "None";
  e[e.Scale = 1] = "Scale";
  e[e.FromTop = 2] = "FromTop";
  e[e.FromBottom = 3] = "FromBottom";
  e[e.FromLeft = 4] = "FromLeft";
  e[e.FromRight = 5] = "FromRight";
  e[e.FadeIn = 6] = "FadeIn";
})(l || (l = {}));
(function (e) {
  e[e.None = 0] = "None";
  e[e.EaseIn = 1] = "EaseIn";
  e[e.EaseBounceOut = 2] = "EaseBounceOut";
  e[e.EasebackOut = 3] = "EasebackOut";
})(c || (c = {}));
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_BaseUIPopup = /* */function (_a$BaseUI) {
  function _ctor() {
    var _this2;
    babel_classCallCheck(this, _ctor);
    _this2 = _callSuper(this, _ctor, arguments);
    _this2.selfmask = true;
    _this2._maske = null;
    _this2._maskeType = r.None;
    _this2._openType = l.Scale;
    _this2._easeType = c.EaseIn;
    _this2._content = null;
    return _this2;
  }
  babel_inherits(_ctor, _a$BaseUI);
  return babel_createClass(_ctor, [{
    key: "maskeType",
    get() {
      if (null == this._maske || 0 == cc.isValid(this._maske, true)) {
        this._maske = this.node.getChildByName("mask");
        if (null == this._maske && this.selfmask) {
          this._maske = new cc.Node("mask");
          var _e = this._maske.addComponent(cc.Widget);
          _e.isAlignBottom = _e.isAlignTop = _e.isAlignRight = _e.isAlignLeft = true;
          var _t2 = this.node.width < this.node.height;
          _e.left = _e.right = _t2 ? 0 : -350;
          _e.top = _e.bottom = _t2 ? -350 : 0;
          this._maske.setParent(this.node);
          this._maske.opacity = 120;
          this._maske.addComponent(cc.BlockInputEvents);
          this._maske.zIndex = -1;
        }
        this.maskeType = this._maskeType;
      }
      return this._maskeType;
    },
    set(e) {
      var _this3 = this;
      this._maskeType = e;
      if (this._maske) {
        if (this._maskeType == r.None || this._maskeType == r.Dim) {
          this._maske.removeComponent(cc.Sprite);
        } else if (this._maskeType == r.Dark) {
          cc.loader.loadRes("texture/singleColor", cc.SpriteFrame, function (e, t) {
            if (!e) {
              var _e2 = $2ccUtil.default.addCompment(_this3._maske, cc.Sprite);
              _e2.sizeMode = cc.Sprite.SizeMode.CUSTOM;
              _e2.type = cc.Sprite.Type.SLICED;
              _e2.spriteFrame = t;
            }
          }), this._maske.color = cc.color(0, 0, 0);
        }
      }
    }
  }, {
    key: "openType",
    get() {
      return this._openType;
    },
    set(e) {
      this._openType = e;
    }
  }, {
    key: "easeType",
    get() {
      return this._easeType;
    },
    set(e) {
      this._easeType = e;
    }
  }, {
    key: "content",
    get() {
      if ((null == this._content || 0 == cc.isValid(this._maske, true)) && (this._content = this.node.getChildByName("content"), null == this._content)) {
        this._content = new cc.Node("content");
        var _e3 = this._content.addComponent(cc.Widget);
        _e3.isAlignBottom = _e3.isAlignTop = _e3.isAlignRight = _e3.isAlignLeft = true;
        _e3.top = _e3.bottom = _e3.left = _e3.right = 0;
        this._content.setParent(this.node);
      }
      return this._content;
    },
    set(e) {
      this._content = e;
    }
  }, {
    key: "onShow",
    value: function onShow() {
      babel_get(babel_getPrototypeOf(_ctor.prototype), "onShow", this).call(this);
      this.showPosture();
    }
  }, {
    key: "closePosture",
    value: function closePosture(e) {
      if (!this.content) {
        return;
      }
      var t = {};
      switch (this.openType) {
        case l.Scale:
          t.scale = 0;
          break;
        case l.FromTop:
          t.y = 800;
          break;
        case l.FromBottom:
          t.y = -800;
          break;
        case l.FromLeft:
          t.x = -400;
          break;
        case l.FromRight:
          t.x = 400;
          break;
        case l.FadeIn:
          t.opacity = 0;
          break;
        default:
          return;
      }
      var n = this.content.getComponent(cc.Widget);
      if (n) {
        n.updateAlignment();
        n.enabled = false;
      }
      var o = this.easeType == c.EaseBounceOut ? .6 : .3;
      o = 1;
      var i = "smooth";
      switch (this.easeType) {
        case c.EaseIn:
          i = "quadIn";
          break;
        case c.EaseBounceOut:
          i = "bounceOut";
          break;
        case c.EasebackOut:
          i = "backOut";
      }
      cc.Tween.stopAllByTarget(this.content);
      cc.tween(this.content).to(1, t, {
        easing: i
      }).call(function () {
        n && (n.enabled = false);
        e && e();
      }).start();
    }
  }, {
    key: "showPosture",
    value: function showPosture() {
      if (!this.content) {
        return;
      }
      var e = {};
      var t = cc.v2();
      switch (this.openType) {
        case l.Scale:
          this.content.scale = 0;
          e.scale = 1;
          break;
        case l.FromTop:
          t = cc.v2(0, 800);
          e.x = e.y = 0;
          break;
        case l.FromBottom:
          t = cc.v2(0, -800);
          e.x = e.y = 0;
          break;
        case l.FromLeft:
          t = cc.v2(-400, 0);
          e.x = e.y = 0;
          break;
        case l.FromRight:
          t = cc.v2(400, 0);
          e.x = e.y = 0;
          break;
        case l.FadeIn:
          this.content.opacity = 0;
          e.opacity = 255;
          break;
        default:
          return;
      }
      var n = this.content.getComponent(cc.Widget);
      if (n) {
        n.updateAlignment();
        n.enabled = false;
      }
      this.content.setPosition(t);
      var o = this.easeType == c.EaseBounceOut ? .3 : .2;
      var i = "smooth";
      switch (this.easeType) {
        case c.EaseIn:
          i = "quadIn";
          break;
        case c.EaseBounceOut:
          i = "bounceOut";
          o = .6;
          break;
        case c.EasebackOut:
          i = "backOut";
          o = .5;
      }
      cc.Tween.stopAllByTarget(this.content);
      cc.tween(this.content).to(o, e, {
        easing: i
      }).call(function () {
        n && (n.enabled = false);
      }).start();
      if (this._maske) {
        this._maske.opacity = 0;
        cc.Tween.stopAllByTarget(this._maske);
        cc.tween(this._maske).to(o, {
          opacity: 120
        }).start();
      }
    }
  }]);
}($2BaseUI.BaseUI);
def_BaseUIPopup.className = "BaseUIPopup";
def_BaseUIPopup.layertype = $2UIManager.layerType.Popup;
def_BaseUIPopup.isMask = true;
def_BaseUIPopup.automatic = true;
cc__decorate([ccp_property], def_BaseUIPopup.prototype, "_maske", undefined);
cc__decorate([ccp_property], def_BaseUIPopup.prototype, "_maskeType", undefined);
cc__decorate([ccp_property({
  type: cc.Enum(r),
  tooltip: "遮罩类型：透明，变暗，模糊",
  visible() {
    return this.selfmask;
  }
})], def_BaseUIPopup.prototype, "maskeType", null);
cc__decorate([ccp_property], def_BaseUIPopup.prototype, "_openType", undefined);
cc__decorate([ccp_property({
  type: cc.Enum(l),
  tooltip: "弹窗跳出类型"
})], def_BaseUIPopup.prototype, "openType", null);
cc__decorate([ccp_property], def_BaseUIPopup.prototype, "_easeType", undefined);
cc__decorate([ccp_property({
  type: cc.Enum(c),
  tooltip: "弹窗缓动类型",
  visible() {
    return this.openType != l.None;
  }
})], def_BaseUIPopup.prototype, "easeType", null);
cc__decorate([ccp_property(cc.Node)], def_BaseUIPopup.prototype, "_content", undefined);
cc__decorate([ccp_property({
  type: cc.Node
})], def_BaseUIPopup.prototype, "content", null);
def_BaseUIPopup = cc__decorate([ccp_ccclass], def_BaseUIPopup);
exports.default = def_BaseUIPopup;